﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcVietAir.Models;

namespace MvcVietAir.Controllers
{
    public class FlightController : Controller
    {
        private RepositoryFlights repoFlight = new RepositoryFlights();
        string HangHK;
        string LoaiVe;
        string HangVe;
        string NoiDi;
        string NoiDen;
        DateTime NgayDi, NgayVe;

        //
        // GET: /Flight/


        // da lsahjghj (dhb)
        public ActionResult Index()
        {
            if (Request.QueryString["NgayVe"].ToString() != "" && Request.QueryString["NgayDi"].ToString() != "")
            {
                string date = Request.QueryString["NgayVe"].ToString();
                string[] d = date.Split('/');
                date = d[1] + "/" + d[0] + "/" + d[2];
                NgayVe = DateTime.Parse(date);
                HangHK = Request.QueryString["HangHK"];
                LoaiVe = Request.QueryString["LoaiVe"];
                HangVe = Request.QueryString["HangVe"];
                NoiDi = Request.QueryString["NoiDi"];
                NoiDen = Request.QueryString["NoiDen"];

                string date1 = Request.QueryString["NgayDi"].ToString();
                string[] d1 = date1.Split('/');
                date1 = d1[1] + "/" + d1[0] + "/" + d1[2];
                NgayDi = DateTime.Parse(date1);
            }
            List<Flight> l1 = null;
            List<Flight> l2 = null;
            if (LoaiVe != "" && LoaiVe == "Khứ hồi"&& NgayDi!=null&&NgayVe!=null)
            {
                l2 = repoFlight.FindFlights(HangHK, NgayVe, NoiDen, NoiDi);
            }

            l1 = repoFlight.FindFlights(HangHK, NgayDi, NoiDi, NoiDen);

            ViewData["LuotDi"] = l1;
            ViewData["LuotVe"] = l2;
            return View();
        }

        public ActionResult Details(string id)
        {
            return View();
        }
    }
}
